﻿namespace Stock.Model
{
    public class AppConfigModel
    {
        /// <summary>
        /// 开机启动 1=启动 0=不启动
        /// </summary>
        public int AutoStart { get; set; }

        /// <summary>
        /// 当前时间更新频率(秒 1-1000)
        /// </summary>
        public int CurrentTimeInterval { get; set; }

        /// <summary>
        /// 信息框类型 1=消息通知模式 2=固定模式
        /// </summary>
        public int InfoType { get; set; }

        /// <summary>
        /// 信息框位置 0=右上角,1=右中间,2=右下角
        /// </summary>
        public int InfoPosition { get; set; }

        /// <summary>
        /// 非工作时间是否显示信息框
        /// </summary>
        public bool NotWorkTimeShowInfo { get; set; }

        /// <summary>
        /// 信息框刷新频率(单位秒 范围1-1000)
        /// </summary>
        public int InfoShowTimeInterval { get; set; }

        /// <summary>
        /// 信息框停留时间(单位秒 范围1-1000)
        /// </summary>
        public int InfoWaitTimeInterval { get; set; }

        /// <summary>
        /// 股票刷新频率(单位秒 范围3-1000)
        /// </summary>
        public int StockShowTimeInterval { get; set; }

        /// <summary>
        /// 股票上涨颜色值
        /// </summary>
        public string ZhangColor { get; set; }

        /// <summary>
        /// 股票下跌颜色值
        /// </summary>
        public string DieColor { get; set; }

        /// <summary>
        /// 固定信息框背景颜色值
        /// </summary>
        public string SpriteBgColor { get; set; }

        /// <summary>
        /// 皮肤设置 0=默认,1=暗黑,2=未知
        /// </summary>
        public int SkinType { get; set; }

        public int StockSadSwich { get; set; }

        public double StockSadPercent { get; set; }

        public int StockHappySwich { get; set; }

        public double StockHappyPercent { get; set; }

        public AppConfigModel()
        {
            AutoStart = 1;
            SkinType = 0;
            NotWorkTimeShowInfo = true;
            InfoType = 2;
            InfoPosition = (int)GrowlInfoPosition.RightMiddle;
            CurrentTimeInterval = 1;
            InfoShowTimeInterval = 5;
            InfoWaitTimeInterval = 4;
            StockShowTimeInterval = 5;
            ZhangColor = AppConst.VALUE_ZHANG_COLOR;
            DieColor = AppConst.VALUE_DIE_COLOR;
            SpriteBgColor = AppConst.VALUE_SPRITE_BG_COLOR;

            StockSadSwich = 1;
            StockSadPercent = -2;
            StockHappySwich = 1;
            StockHappyPercent = 2;
        }

        public void Valid()
        {
            if (!(0 <= AutoStart && AutoStart <= 1))
            {
                AutoStart = 1;
            }

            int skin = SkinType;
            if (!(0 <= skin && skin <= 2))
            {
                SkinType = 0;
            }

            if (!(1 <= InfoType && InfoType <= 2))
            {
                InfoType = 1;
            }

            if (!(0 <= InfoPosition && InfoPosition <= 2))
            {
                InfoPosition = 0;
            }

            if (CurrentTimeInterval < 1 || CurrentTimeInterval > 1000)
            {
                CurrentTimeInterval = 1;
            }

            if (InfoShowTimeInterval < 1 || InfoShowTimeInterval > 1000)
            {
                InfoShowTimeInterval = 3;
            }

            if (InfoWaitTimeInterval < 1 || InfoWaitTimeInterval > 1000)
            {
                InfoWaitTimeInterval = 3;
            }

            if (StockShowTimeInterval < 3 || StockShowTimeInterval > 1000)
            {
                StockShowTimeInterval = 3;
            }

            if (StockSadPercent >= 0)
            {
                StockSadPercent = -2;
            }

            if (StockHappyPercent <= 0)
            {
                StockSadPercent = 2;
            }
        }

        public AppConfigModel Copy()
        {
            AppConfigModel model = new AppConfigModel
            {
                AutoStart = AutoStart,
                SkinType = SkinType,
                SpriteBgColor = SpriteBgColor,
                DieColor = DieColor,
                ZhangColor = ZhangColor,
                StockShowTimeInterval = StockShowTimeInterval,
                InfoWaitTimeInterval = InfoWaitTimeInterval,
                CurrentTimeInterval = CurrentTimeInterval,
                InfoType = InfoType,
                InfoPosition = InfoPosition,
                NotWorkTimeShowInfo = NotWorkTimeShowInfo,
                InfoShowTimeInterval = InfoShowTimeInterval,
                StockSadSwich = StockSadSwich,
                StockSadPercent = StockSadPercent,
                StockHappySwich = StockHappySwich,
                StockHappyPercent = StockHappyPercent
            };
            return model;
        }

        public void Update(AppConfigModel model)
        {
            AutoStart = model.AutoStart;
            SkinType = model.SkinType;
            SpriteBgColor = model.SpriteBgColor;
            DieColor = model.DieColor;
            ZhangColor = model.ZhangColor;
            StockShowTimeInterval = model.StockShowTimeInterval;
            InfoWaitTimeInterval = model.InfoWaitTimeInterval;
            CurrentTimeInterval = model.CurrentTimeInterval;
            InfoType = model.InfoType;
            InfoPosition = model.InfoPosition;
            NotWorkTimeShowInfo = model.NotWorkTimeShowInfo;
            InfoShowTimeInterval = model.InfoShowTimeInterval;
            StockSadSwich = model.StockSadSwich;
            StockSadPercent = model.StockSadPercent;
            StockHappySwich = model.StockHappySwich;
            StockHappyPercent = model.StockHappyPercent;
        }

        public bool IsOpenSadSwich()
        {
            return StockSadSwich > 0;
        }

        public bool IsOpenHappySwich()
        {
            return StockHappySwich > 0;
        }
    }
}
